unit rcdLog;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, RzTabs, RzButton;

type
  Trcdlogfrm = class(TForm)
    pal_ctrl: TPanel;
    btnClose: TSpeedButton;
    labcaption: TLabel;
    PageControl: TRzPageControl;
    palMenu: TPanel;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    RzBitBtn3: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    RzBitBtn5: TRzBitBtn;
    RzBitBtn6: TRzBitBtn;
    procedure pal_ctrlResize(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure PageControlDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn5Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    RcdCount:integer;
    procedure CreateOneRcd(tabname:string);
  end;

var
  rcdlogfrm: Trcdlogfrm;

implementation

{$R *.dfm}
uses
  includefile, OneRcd;

procedure Trcdlogfrm.pal_ctrlResize(Sender: TObject);
begin
   btnClose.Left:=pal_ctrl.Width-btnClose.Width-3;
end;

procedure Trcdlogfrm.btnCloseClick(Sender: TObject);
begin
  hide;
end;

procedure TRcdLogfrm.CreateOneRcd(tabname:string);
var
  RzTabSheet:TRzTabSheet;
  ChildRcd:TOneRcdfram;
begin
  RzTabSheet:=TRzTabSheet.Create(PageControl);
  RzTabSheet.PageControl:=PageControl;
  RzTabSheet.Caption:=tabname;
  PageControl.ActivePage:=RzTabSheet;
  ChildRcd:=TOneRcdfram.Create(RzTabSheet);
  with ChildRcd do begin
    Parent:=RzTabSheet;
    Left:=0;
    Top:=0;
    Name:=tabname;
    Caption:=tabname;
    IniWindows;
    Show;
  end;
  exSleep(100);
  inc(RcdCount);
end;

procedure Trcdlogfrm.RzBitBtn1Click(Sender: TObject);
begin
  CreateOneRcd('TEMPDATA'+Trim(inttostr(RcdCount)));
end;

procedure Trcdlogfrm.PageControlDblClick(Sender: TObject);
var
  RzTabSheet:TRzTabSheet;
begin
  if PageControl.PageCount>1 then begin
    RzTabSheet:=PageControl.FindNextPage(PageControl.ActivePage,True,True);
    if TOneRcdfram(PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption)).CloseWindow then
    begin
      PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption).Free;
      PageControl.ActivePage.Free;
      PageControl.ActivePage:=RzTabSheet;
    end;
  end else begin
    if TOneRcdfram(PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption)).CloseWindow then
    begin
      PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption).Free;
      PageControl.ActivePage.Free;
    end;
  end;
end;

procedure Trcdlogfrm.FormCreate(Sender: TObject);
var
  I:integer;
begin
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption(name,TLabel(Components[I]).Tag);
    end;
    if Components[I] is TRzBitBtn then begin
      if 0<>TRzBitBtn(Components[I]).Tag then
        TRzBitBtn(Components[I]).Caption:=
                GetCaption(name,TRzBitBtn(Components[I]).Tag);
    end;
  end;
  RcdCount:=1;
  CreateOneRcd('TEMPDATA'+Trim(inttostr(RcdCount)));
end;

procedure Trcdlogfrm.RzBitBtn5Click(Sender: TObject);
begin
  if PageControl.PageCount>=1 then
    TOneRcdfram(PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption)).iniSerial;
end;

procedure Trcdlogfrm.FormClose(Sender: TObject; var Action: TCloseAction);
var
  I:integer;
begin
  self.Show;
  bCanClose:=True;
  if PageControl.PageCount>0 then begin
    for I:=PageControl.PageCount-1 downto 0 do begin
      if not TOneRcdfram(PageControl.Pages[I].FindChildControl(PageControl.Pages[I].Caption)).CloseWindow then begin
        Action:=caNone;
        bCanClose:=False;
        Exit;
      end;
    end;
  end;
end;

procedure Trcdlogfrm.RzBitBtn3Click(Sender: TObject);
begin
  if PageControl.PageCount>=1 then
    TOneRcdfram(PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption)).export2xls;
end;

procedure Trcdlogfrm.RzBitBtn4Click(Sender: TObject);
begin
  if PageControl.PageCount>=1 then
    TOneRcdfram(PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption)).startSerial;
end;

procedure Trcdlogfrm.FormShow(Sender: TObject);
begin
  //CreateOneRcd('TEMPDATA'+Trim(inttostr(RcdCount)));
end;

procedure Trcdlogfrm.RzBitBtn2Click(Sender: TObject);
begin
  if PageControl.PageCount>=1 then
    TOneRcdfram(PageControl.ActivePage.FindChildControl(PageControl.ActivePage.Caption)).saveRcd;
end;

end.
